package Triangulation.minimalityMetrics;

import datatypes.Edge;
import datatypes.FaceSet;
import datatypes.Triangle;
import datatypes.list.LinkedList;

public abstract class AbstractMinimalityMetric implements MinimalityMetric {

	@Override
	public boolean localMinimumExistsForEdge(Edge edge, FaceSet set) {
		
		// Get all the empty triangles adjacent to this particular edge.
		LinkedList<Triangle> trianglesLeft = edge.getTrianglesLeft();
		LinkedList<Triangle> trianglesRight = edge.getTrianglesRight();
		
		while (trianglesLeft.hasNext()) {
			Triangle triLeft = trianglesLeft.next();
			while (trianglesRight.hasNext()) {
				Triangle triRight = trianglesRight.next();
				if (edgeIsLocallyMinimal(edge, triLeft, triRight)) {
					// If we find ANY local minimum for the edge e, it means that the edge
					// e remains a candidate, and cannot be removed
					
					// moving the index of the trianglesList to the previous position to 
					// make sure the next time the exact same set of triangles is
					// tested first again. The same set will most likely return true
					// again causing a significant speedup!
					trianglesLeft.previous();
					trianglesRight.previous();
					return true;
				}
			}
			trianglesRight.moveToHead();
//			set.removeTriangle(triLeft);	// too slow!
		}
		return false;
	}
	
	public boolean betaSkeletonApplicable() {
		return false;
	}

}
